import { Module } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { consoleTransports, createDailyRotateTransport } from './createRotateTransport';
import { WinstonModule } from 'nest-winston';

@Module({
    imports: [
        WinstonModule.forRootAsync({
            inject: [ConfigService],
            useFactory: (configService: ConfigService) => {
                const logOn = configService.get<string>('LOG_ON') === 'true';
                return {
                    transports: [consoleTransports, ...(logOn ? [createDailyRotateTransport('info', 'info.log'), createDailyRotateTransport('error', 'error.log')] : [])],
                };
            },
        }),
    ],
    controllers: [],
    providers: [],
})
export class LogsModule {}
